import { handleActions } from 'redux-actions'
import { CHANGE, GETITEMLIST } from '../types/lectureList'

const defaultState = {
	list: []
}

export default handleActions({
	[GETITEMLIST]( state , action ){
		action.payload.list.forEach(item => {
			item.learnNumber = Math.floor(Math.random() * (300 - 30) + 30)
		})
		state.list.push.apply(state.list, action.payload.list)
		return {
			...state
		}
	},
	[CHANGE]( state , action ){
		let i = action.payload
		i && state.list.forEach((item, index) => {
			if (item.id === i.id) {
				for (let obj in i) {
					state.list[index][obj] = i[obj]
				}
			}
		})
		return {
			...state
		}
	}
}, defaultState)
